<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="perm" uri="/WEB-INF/tld/perm.tld"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<script>
	var ctx = "${ctx}";
</script>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>新发现管理</title>
<meta name="keywords"
	content="体验,友好,高级管理台,易用,高性能,高扩展性,bootstrap框架,响应式后台">
<meta name="description"
	content="这是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
<meta http-equiv="expires" content="Wed, 26 Feb 209908:21:57 GMT">

<link rel="shortcut icon" href="favicon.ico">
<link href="${ctx}/static/css/bootstrap.min.css?v=${static_version}/"
	rel="stylesheet">
<link
	href="${ctx}/static/css/font-awesome.min.css?v=4.4.0?v=${static_version}/"
	rel="stylesheet">
<link
	href="${ctx}/static/css/plugins/footable/footable.core.css?v=${static_version}/"
	rel="stylesheet">
<link
	href="${ctx}/static/css/plugins/summernote/summernote.css?v=${static_version}/"
	rel="stylesheet">
<link
	href="${ctx}/static/css/plugins/summernote/summernote-bs3.css?v=${static_version}/"
	rel="stylesheet">
<link
	href="${ctx}/static/plugins/laypage/laypage.css?v=${static_version}"
	rel="stylesheet">
<link
	href="${ctx}/static/css/plugins/iCheck/custom.css?v=${static_version}/"
	rel="stylesheet">
<link
	href="${ctx}/static/css/plugins/chosen/chosen.css?v=${static_version}/"
	rel="stylesheet">
<link href="${ctx}/static/css/animate.min.css?v=${static_version}/"
	rel="stylesheet">
<link
	href="${ctx}/static/js/plugins/layer/laydate/laydate.css?v=${static_version}/"
	rel="stylesheet">
<link
	href="${ctx}/static/css/plugins/webuploader/webuploader.css?v=${static_version}/"
	rel="stylesheet">
<link
	href="${ctx}/static/css/plugins/switchery/switchery.css?v=${static_version}/"
	rel="stylesheet">
<link href="${ctx}/static/css/style.min.css?v=${static_version}/"
	rel="stylesheet">
<link
	href="${ctx}/static/js/plugins/uploadify/uploadify.css?v=${static_version}/"
	rel="stylesheet">

</head>
<body class="gray-bg">
	<div class="ibox float-e-margins">
		<div class="ibox-content">
			<form class="form-group" id="newfind_table_form">
				<input type="hidden" name="orderBy" value="create_date desc">
				<input type="hidden" id="type-select-id" name="typeId" value="">
				<div class="row">
					<perm:hasPermission code="newfind/find">
						<div class="col-md-2">
							<input name="keyword" type="text" placeholder="请输入标题"
								class="form-control" />
						</div>
						<div class="col-md-4">
							<div class="input-daterange input-group">
								<input id="startTime" type="text"
									class="input-md form-control layer-date" placeholder="开始时间"
									name="startTime"> <span class="input-group-addon">至</span>
								<input id="endTime" type="text"
									class="input-md form-control layer-date" placeholder="结束时间"
									name="endTime">
							</div>
						</div>
						<div class="col-md-2 col-sm-2">
							<select data-placeholder="选择新发现" id="type-select"
								class="input-md form-control chosen-select" tabindex="4">
								<option value="">请选择分类</option>
							</select>
						</div>
						<div class="col-md-1 col-sm-2">
							<button id="newfind_table_search" type="button"
								class="btn btn-outline btn-block btn-primary">查询</button>
						</div>
					</perm:hasPermission>
					<perm:hasPermission code="newfind/insertGet">
						<div class="col-md-1  col-sm-2 pull-right ">
							<a onclick="clickInsertGet()"
								class="btn btn-block btn-outline btn-primary">添加</a>
						</div>
					</perm:hasPermission>
				</div>
			</form>
			<table id="newfind_table" data-action="${ctx}/newfind/find"
				data-datatable="true"
				class="footable table table-stripped toggle-arrow-tiny">
				<thead>
					<tr>
						<th data-sort-ignore="true" data-title="title">标题</th>
						<th data-sort-ignore="true" data-title="typeName">分类</th>
						<th data-sort-ignore="true" data-title="payMoney">支付金额</th>
						<th data-sort-ignore="true" data-title="payStatus"
							data-hide="phone,tablet" data-type="enum"
							data-opt='{"1":"未支付","0":"已支付"}'>支付状态</th>
						<th data-sort-ignore="true" data-title="status"
							data-hide="phone,tablet" data-type="enum"
							data-opt='{"0":"已通过","1":"待审核","2":"审核失败"}'>状态</th>
						<th data-sort-ignore="true" data-title="browse"
							data-hide="phone,tablet">浏览量</th>
						<th data-sort-ignore="true" data-title="createDate"
							data-formater="yyyy-MM-dd" data-type="datetime"
							data-hide="phone,tablet">创建时间</th>
						<th data-sort-ignore="true" data-crudx="true"
							data-title='{"uid":"id"}' data-hide="phone">操作
							<div style="display: none;" class="center hidden-phone">
								<perm:hasPermission code="newfind/upStatus">
									<button data-type='change' data-toge="status,payStatus"
										data-callback=upStatusSuccess data-id=":uid"
										style="margin-left: 3px; margin-top: 3px" type="button"
										class="btn btn-primary btn-xs">启用/禁用</button>
								</perm:hasPermission>
								<perm:hasPermission code="newfind/upStatus">
									<button data-type='change' data-toge="status,payStatus"
										data-callback="upStatusFail" data-id=":uid"
										style="margin-left: 3px; margin-top: 3px" type="button"
										class="btn btn-primary btn-xs">启用/禁用</button>
								</perm:hasPermission>
								<perm:hasPermission code="newfind/updateGet">
									<button data-type='change' data-toge="status,payStatus"
										data-callback="upData" data-id=":uid"
										style="margin-left: 3px; margin-top: 3px" type="button"
										class="btn btn-primary btn-xs">启用/禁用</button>
								</perm:hasPermission>
								<perm:hasPermission code="newfind/delete">
									<button data-type='change' data-toge="status,payStatus"
										data-callback="deldata" data-id=":uid"
										style="margin-left: 3px; margin-top: 3px" type="button"
										class="btn btn-primary btn-xs">启用/禁用</button>
								</perm:hasPermission>
								<perm:hasPermission code="newfind/findcomment">
									<button onclick="clickfindGet(this)" data-id=":uid"
										type="button" style="margin-left: 3px; margin-top: 3px"
										class="btn btn-outline btn-info btn-xs">
										<i class="fa fa-eye"></i>&nbsp;留言
									</button>
								</perm:hasPermission>
							</div>
						</th>
					</tr>
				</thead>
				<tbody>
				</tbody>
			</table>
			<div class="row">
				<div class="col-md-6" class="pull-left" id="page_left_text"></div>
				<div class="col-md-6" id="page_text"></div>
			</div>
		</div>
	</div>

	<script>
		var ctx = "${ctx}"
	</script>
	<script src="${ctx}/static/js/jquery.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/bootstrap.min.js?v=${static_version}"></script>
	<script
		src="${ctx}/static/js/plugins/footable/footable.all.min.js?v=${static_version}"></script>
	<script
		src="${ctx}/static/js/plugins/validate/jquery.validate.min.js?v=${static_version}"></script>
	<script
		src="${ctx}/static/js/plugins/validate/messages_zh.min.js?v=${static_version}"></script>
	<script
		src="${ctx}/static/js/plugins/webuploader/webuploader.min.js?v=${static_version}"></script>
	<script
		src="${ctx}/static/js/plugins/summernote/summernote.min.js?v=${static_version}"></script>
	<script
		src="${ctx}/static/js/plugins/summernote/summernote-zh-CN.js?v=${static_version}"></script>
	<script
		src="${ctx}/static/js/plugins/chosen/chosen.jquery.js?v=${static_version}"></script>
	<script
		src="${ctx}/static/js/plugins/layer/laydate/laydate.js?v=${static_version}"></script>
	<script
		src="${ctx}/static/js/plugins/iCheck/icheck.min.js?v=${static_version}"></script>
	<script
		src="${ctx}/static/plugins/laypage/laypage.js?v=${static_version}"></script>
	<script
		src="${ctx}/static/js/plugins/switchery/switchery.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/eModal.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/cookie.js?v=?v=${static_version}"></script>
	<script
		src="${ctx}/static/common/custom-datatable.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/content.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/contabs.min.js?v=${static_version}"></script>
	<script
		src="${ctx}/static/js/plugins/ueditor-1.4.3/ueditor.config.js?v=${static_version}"></script>
	<script
		src="${ctx}/static/js/plugins/ueditor-1.4.3/ueditor.all.js?v=${static_version}"></script>
	<script
		src="${ctx}/static/js/plugins/uploadify/jquery.uploadify.js?v=${static_version}"></script>
	<script src="${ctx}/static/common/common.js?v=${static_version}"></script>
	<script
		src="${ctx}/static/js/plugins/layer/layer.js?v=${static_version}"></script>

	<script>
		var clickfindGet = function(me) {
			location.href = "${ctx}/newfind/findcomment?id=" + $(me).data("id");
		}

		var upData = function(cData, cLable, row, togeColumn) {
			console.log("---[" + JSON.stringify(togeColumn) + "]");
			if (togeColumn["status"] === 1 && togeColumn["payStatus"] === 1) {
				return '<button onclick="clickUpdateGet(this,0)" data-id=":uid" style="margin-left:3px;margin-top:3px" class="btn btn-info btn-outline btn-xs"><i class="fa fa-pencil"></i>&nbsp;更新</button>';
			}
		}

		var deldata = function(cData, cLable, row, togeColumn) {
			console.log("---[" + JSON.stringify(togeColumn) + "]");
			if (togeColumn["status"] === 1 && togeColumn["payStatus"] === 1) {
				return '<button onclick="deleteData(this,0)" data-id=":uid" style="margin-left:3px;margin-top:3px" class="btn btn-outline btn-danger btn-xs"><i class="fa fa-times"></i>&nbsp;删除</button>';
			}
		}

		var upStatusSuccess = function(cData, cLable, row, togeColumn) {
			console.log("---[" + JSON.stringify(togeColumn) + "]");
			if (togeColumn["status"] === 1 && togeColumn["payStatus"] === 0) {
				return '<button onclick="successStatus(this,0)" data-id=":uid" style="margin-left:3px;margin-top:3px" class="btn btn-outline btn-warning btn-xs"><i class="fa fa-warning"></i>&nbsp;通过</button>';
			}
		}

		var upStatusFail = function(cData, cLable, row, togeColumn) {
			console.log("---[" + JSON.stringify(togeColumn) + "]");
			if (togeColumn["status"] === 1 && togeColumn["payStatus"] === 0) {
				return '<button onclick="failStatusmodify(this,2)" data-id=":uid" style="margin-left:3px;margin-top:3px" class="btn btn-outline btn-warning btn-xs"><i class="fa fa-warning"></i>&nbsp;驳回</button>';
			}
		}
		var clickfindcomment = function(me) {
			location.href = "${ctx}/newfind/findcomment?id=" + $(me).data("id");
		}
		var deleteData = function(me) {
			$.confirm({
				text : "确定删除此条信息吗!",
				confirm : function() {
					$.ajax({
						url : "${ctx}/newfind/delete",
						title : '删除此条信息！',
						data : {
							id : $(me).data("id")
						},
						type : 'POST',
						dataType : 'json',
						success : function(response) {
							if (response.code == 0) {
								$("#newfind_table_search").click();
								layer.msg('删除成功！', {
									icon : 1
								});
							} else {
								layer.msg('删除失败！', {
									icon : 5
								});
							}
						}
					});
				},
				cancel : function() {
					return true;
				}
			});
		}

		var failStatusmodify = function(me) {
			layer.prompt({
				formType : 2,
				title : '拒绝原因，必须填写！'
			}, function(value) {
				$.ajax({
					url : "${ctx}/newfind/upStatus",
					title : "aaa",
					loading : true,
					data : {
						reason : value,
						status : 2,
						id : $(me).data("id")
					},
					type : 'POST',
					success : function(response) {
						if (response.code == 0) {
							eModal.close();
							$("#newfind_table_search").click();
						} else {
							$.confirm({
								cancelButton : "关   闭",
								title : '提示',
								text : "重置用户密码错误!"
							});
						}
					}
				});
				layer.msg('已驳回！', {
					icon : 1
				});
			});
			// layer.close(index);
		}

		var successStatus = function(me) {
			$.ajax({
				url : "${ctx}/newfind/upStatus",
				title : '审核成功',
				loading : true,
				data : {
					status : 0,
					reason : "审核成功！",
					id : $(me).data("id")
				},
				type : 'POST',
				success : function(response) {
					if (response.code == 0) {
						$("#newfind_table_search").click();
						layer.msg('审核成功！', {
							icon : 1
						});
					} else {
						layer.msg('审核信息提交失败！', {
							icon : 5
						});
					}
				}
			});
		}

		var ue;

		$(document).ready(function() {
			init_page_datatable();
		});

		var clickUpdateGet = function(me) {
			eModal.ajax({
				url : "${ctx}/newfind/updateGet?id=" + $(me).data("id"),
				title : '修改新发现',
				loading : true,
				subtitle : '',
				buttons : [
						{
							text : '保存',
							style : 'info',
							close : false,
							click : function() {
								if (!jQuery.checkall(true))
									return;
								var images = [];
								$(".imageUploadify img").each(function() {
									images.push($(this).attr("src"));
								})
								var data = {
									title : $("#title").val(),
									image : images.toString(),
									url : $("#url").val(),
									content : $("#content").val(),
									payMoney : $("#payMoney").val(),
									enabled : $("[name='enabled']").is(
											":checked") ? 0 : 1,
									typeId : $("#typeId").val(),
									token : $("#token").val(),
									id : $("#id").val()
								};
								$.ajax({
									url : '${ctx}/newfind/update',
									type : 'POST',
									dataType : 'json',
									data : JSON.stringify(data),
									contentType : "application/json",
									success : function(response) {
										if (response.code == 0) {
											eModal.close();
											$("#newfind_table_search").click();
											parent.layer.msg('信息已保存，如需支付，请移至app端！');
										} else {
											eModal.close();
											parent.layer.msg('输入信息有误,添加新发现失败！',
													{
														icon : 2
													});
										}
									}
								});
							}
						}, {
							text : '取消',
							style : 'danger',
							close : false,
							click : function() {
								eModal.close();
							}
						} ],
			});
		}

		var clickInsertGet = function() {
			eModal.ajax({
				url : "${ctx}/newfind/insertGet",
				title : '添加新发现',
				loading : true,
				subtitle : '',
				buttons : [ {
					text : '保存',
					style : 'info',
					close : false,
					click : function() {
						if (!jQuery.checkall(true))
							return;
						var images = [];
						$(".imageUploadify img").each(function() {
							images.push($(this).attr("src"));
						})
						var data = {
							title : $("#title").val(),
							image : images.toString(),
							url : $("#url").val(),
							content : $("#content").val(),
							payMoney : $("#payMoney").val(),
							typeId : $("#typeId").val(),
							createDate : $("#createDate").val(),
							token : $("#token").val()
						};
						$.ajax({
							url : '${ctx}/newfind/add',
							type : 'POST',
							dataType : 'json',
							data : JSON.stringify(data),
							contentType : "application/json",
							success : function(response) {
								if (response.code == 0) {
									eModal.close();
									$("#newfind_table_search").click();
									parent.layer.msg('信息已保存，如需支付，请移至app端！');
								} else {
									eModal.close();
									parent.layer.msg('输入信息有误,添加新发现失败！', {
										icon : 2
									});
								}
							}
						});
					}
				}, {
					text : '取消',
					style : 'danger',
					close : false,
					click : function() {
						eModal.close();

					}
				} ],
			});

		}

		$(function() {

			jQuery.searchFormInit();

			$.ajax({
				url : '${ctx}/newfindType/list',
				type : 'POST',
				dataType : 'json',
				success : function(response) {
					if (response.code == 0) {
						var html = [];
						var data = response.data || [];
						for (var i = 0; i < data.length; i++) {
							html.push('<option value="'+data[i].id+'">'
									+ data[i].name + '</option>');
						}
						$("#type-select").append(html.join(""));
						$("#type-select").trigger("chosen:updated");
					}
				}
			});

			$("#type-select").chosen({
				width : '100%'
			}).change(function(event) {
				$("#type-select-id").val($(event.target).val());
			});

		});
	</script>

</body>
</html>